package com.lyrcsoft.rxjava1x.operators.convert;

import lombok.extern.slf4j.Slf4j;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fujc2dev@126.com
 * @date 2024-11-19
 */
@Slf4j
public class Rx1concatMap {
    public static void main(String[] args) {
        log.debug("----------- rxJavaConcatMap ---------");
        List<Student> students = new ArrayList<>();
        List<Source> sources = new ArrayList<>();
        sources.add(new Source(1, "化学", 80));
        sources.add(new Source(2, "物理", 79));
        sources.add(new Source(3, "生物", 78));
        students.add(new Student("小明1", 1, sources));
        students.add(new Student("小明2", 1, sources));
        // 上例是一个学生与分数的集合，
        Observable.from(students)
                .concatMap(new Func1<Student, Observable<Source>>() {
                    @Override
                    public Observable<Source> call(Student student) {
                        log.debug("Item: " + student.name);
                        // 返回的是一个序列，序列，序列
                        return Observable.from(student.mSources);
                    }
                })
                .subscribe(new Action1<Source>() {
                    @Override
                    public void call(Source source) {
                        log.debug("Item: " + source + " 执行调用 获取线程id:" + Thread.currentThread().getId());
                    }
                });

    }
}
